package com.mybatis.mapper;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.mybatis.entity.BlogUser;

public class BlogUserMapperTester {
	
	private static SqlSessionFactory sessionFactory = null;
	private static SqlSession session = null;
	
	@Before
	public void init() throws IOException{
		
		System.out.println("test begin");
		
		String configResource = "Configuration.xml";
		
		Reader reader = Resources.getResourceAsReader(configResource);
		
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		
		sessionFactory = builder.build(reader);
		
		session =  sessionFactory.openSession();
	}
	
	@After
	public void afterMethodInvoke(){
		
		session.close();
		
		System.out.println("test end");

	}
	
	@Test
	public void testFindBlogById() throws IOException{
		
		BlogUserMapper blogUserMapper = session.getMapper(BlogUserMapper.class);
		
		BlogUser blogUser = blogUserMapper.selectBlogUserById(1);
		
		System.out.println(blogUser);
		
		System.out.println("test");
	}
	
	@Test
	public void testselectAllBlog() throws IOException{
		
		BlogUserMapper blogUserMapper = session.getMapper(BlogUserMapper.class);
		
		List<BlogUser> blogUserlist = blogUserMapper.selectAllBlogUser();

		System.out.println(blogUserlist);
	}
}
